﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;
using LTM_Extra;

namespace LTM_Main
{
    public partial class LTMToolbar : OfficeRibbon
    {
        public LTMToolbar()
        {
            InitializeComponent();
        }
        
        private void LTMToolbar_Load(object sender, RibbonUIEventArgs e)
        {
            try
            {
                ContentProvider provider = new ContentProvider();
               
                if (!ContentProvider.IsAdmin())
                {
                    btnVar.Enabled = false;
                }
                styleGallery.Enabled = false;
  
            }
            catch (Exception ex) 
            {

                MessageBox.Show(ex.ToString());
            }

        }


        private void btnSetting_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                ManagingSettings settings = new ManagingSettings();
                settings.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btnAuth_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                ManagingAuthors author = new ManagingAuthors();
                author.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        IDictionary<string, Style> styles = null;
        private void btnDoc_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                ContentProvider provider = new ContentProvider();

                if (!provider.TemplateFolderIsConfigured())
                {

                    MessageBox.Show("Please configure the template folder first.");
                    return;
                }

                if (provider.GetAuthorList().Count == 0)
                {
                    MessageBox.Show("There is no pre-defined author.");
                    return;
                }

                CreationDocument doc = new CreationDocument(styleGallery);
                doc.ShowDialog();
               
                styles = Helper.GetStylesFromTemplate(provider);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }

        }

        private void btnVar_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                ContentProvider provider = new ContentProvider();
               
                if (!provider.TemplateFolderIsConfigured())
                {

                    MessageBox.Show("Please configure the template folder first.");
                    return;
                }

                ManagingVariables variables = new ManagingVariables();
                variables.ShowDialog();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void styleGallery_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {


                string styleName = styleGallery.SelectedItem.Tag.ToString();

                Microsoft.Office.Interop.Word.Style style = styles[styleName].WordStyle;
                Helper.ApplyStyleToSelection(style);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }

        }

       

        private void hsGallery_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                ContentProvider provider = new ContentProvider();
                switch (hsGallery.SelectedItem.Tag.ToString())
	            {
                     case   Constants.TagHideLogo:
                        Helper.HideLogo();
                        break;
                     case Constants.TagShowLogo:
                        Helper.ShowLogo();
                        break;
                    case Constants.TagHideFooter:
                        Helper.HideFooter();
                        break;
                    case Constants.TagShowFooter:
                        Helper.ShowFooter();
                        break;
                    case Constants.TagShowAddress:
                        Helper.ShowCompanyAddress(provider);
                        break;
                    case Constants.TagHideAddress:
                        Helper.HideCompanyAddress(provider);
                        break;

            		
	            }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
            
            

           
        }

    }
}
